package com.honour.controller.interfaced;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.honour.service.interfaced.UserInManager;
import com.honour.service.interfaced.impl.EnergyInService;
import com.system.controller.base.BaseController;
import com.system.util.AppUtil;
import com.system.util.PageData;
import com.system.util.Tools;

/**
 @Function 能量值接口
 @Author zhaozhenhua
 @Date   2017年12月13日
*/

@Controller
@RequestMapping(value="/appengrgyin")
public class EnergyInController extends BaseController{
	
	@Resource(name="energyInService")
	private EnergyInService energyInService;
	
	@Resource(name="userinService")
	private UserInManager userinService;
	
	
	/**
	 * 获取所有能量组成
	 * @Author zhaozhenhua
	 * @date   2017年12月13日
	 * @return
	 */
	@RequestMapping(value="/energylist")
	@ResponseBody
	public Object getEnergyList(){
		logBefore(logger, "获取所有能量组成");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("ENERGYLIST", pd.getString("FKEY"))){	//检验请求key值是否合法
					if(AppUtil.checkParam("sDistance", pd)){	//检查参数
						List<PageData> list = energyInService.getEnergyList(pd);
						PageData energyScore = userinService.getEnergyScore(pd);
						for (PageData p : list) {
							//根据能量值ID获取能量分值组成列表
							List<PageData> compList = energyInService.getEnergyCompList(p);
							p.put("compList",compList );
							if("购物分".equals(p.getString("NAME"))){
								p.put("SCORE",energyScore.getInterger("SHOPSCORE"));
							}if("活动分".equals(p.getString("NAME"))){
								p.put("SCORE", energyScore.getInterger("ACTIVITYSCORE"));
							}if("互动分".equals(p.getString("NAME"))){
								p.put("SCORE", energyScore.getInterger("INTERACTSCORE"));
							}if("基础分".equals(p.getString("NAME"))){
								p.put("SCORE", energyScore.getInterger("BASISSCORE"));
							}if("荣耀分".equals(p.getString("NAME"))){
								p.put("SCORE", energyScore.getInterger("HONOURSCORE"));
							}
						}
						if (list.size()!=0) {
							map.put("pd", list);
						}
						result = (0 == list.size()) ?  "02" :  "01";
					}else {
						result = "03";
					}
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	/**
	 * 按月份统计用户能量值
	 * @Author zhaozhenhua
	 * @date   2017年12月15日
	 * @return
	 */
	@RequestMapping(value="/energyvaluemonth")
	@ResponseBody
	public Object getCommentList(){
		logBefore(logger, "按月份统计用户能量值");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("ENERGYVALUEMONTH", pd.getString("FKEY"))){	//检验请求key值是否合法
				if(AppUtil.checkParam("sDistance", pd)){	//检查参数
					List<PageData> list = energyInService.getEnergyValueByMonth(pd);
					if (list.size()!=0) {
						map.put("pd", list);
					}
					result = (0 == list.size()) ?  "02" :  "01";
				}else {
					result = "03";
				}
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
	
}
